﻿namespace Calendar
{
    internal class Program
    {/// <summary>
    /// calendar
    /// </summary>
    /// <param name="args"></param>
        static void Main(string[] args)
        {int x = 0, y = 0;
            for (int i = 1; i < 13; i++)
            {
                //输出月份
                string Month = i.ToString() + "月";
                char pad = ' ';
                Console.Write(Month.PadLeft(15, pad));
                //输出星期
                Console.SetCursorPosition(x , y + 1);
                Console.Write(" 日  一  二  三  四  五  六");
                //定义初始化日期
                DateTime theDay = new DateTime(2022, i, 1);
                //判断一个月中有多少天
                int days = DateTime.DaysInMonth(theDay.Year, theDay.Month);
                //确定每月第一天是星期几
                int TheFristDay = (int)theDay.DayOfWeek;
                Console.SetCursorPosition(x + 4 * TheFristDay, y + 2);
                //非第一天
                int m = 0;
                for (int j = 1; j <= days; j++)
                {
                    Console.Write("{0,3}", j);
                    Console.Write(" ", 2);
                    //周六换行
                    DateTime dateTime = new DateTime(2022, i, j);
                    if (dateTime.DayOfWeek == DayOfWeek.Saturday)
                    {
                        m++;
                        Console.SetCursorPosition(x , y + 2 + m);
                    }

                }//3，6，9月换行
                if (i % 3 == 0)
                {
                    x = 0;
                    y = y + 10--;

                }
                else { x += 35; }
                Console.SetCursorPosition(x, y);
            }
            Console.ReadKey();
        
        }
    }
}